﻿<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<Plain.Demo.Blog.Business.Post>" MasterPageFile="~/Layout/TwoColumn.master" %>
<asp:Content id="ctnHead" runat="server" ContentPlaceHolderID="Head">
	<script type="text/javascript" >
		$(function() {
			$("#submit").click(function(event){
		    	$.post("<%= Url.Action("CreateComment","Blog") %>", $("#CommentForm").serialize(),
					function(data){
						var comment = $("<div  class=\"Comment\"><h4><img src=\"/Images/comments-24.png\" alt=\"Comment\" />" + data.Author + "</h4><p>" + data.Content + "</p></div>"); 
						$(".AddComment").before(comment);
						comment.hide();
						comment.fadeTo("slow", 0.60);
					});           	 
			});
			InitializeArchive("<%= Url.Action("Archive/Year","Blog") %>","<%= Url.Action("Archive/Month","Blog") %>","<%= Url.Action("Archive/List","Blog") %>");
			YearForward("<%= Url.Action("Archive/Year","Blog") %>","<%= Url.Action("Archive/Month","Blog") %>","<%= Url.Action("Archive/List","Blog") %>");
		});
	</script>
</asp:Content>
<asp:Content id="ctnColumn1" runat="server" ContentPlaceHolderID="Column1">
	<div class="Post">
		<h4><%= Model.Title %></h4>
	    <%= Model.Content %>
	    <span class="DetailTags">
	    	Tags: <% foreach (var tag in Model.Tags) { %>
	    			<%= Html.ActionLink(tag, "ByTag", new { id=tag })%>
	    		  <% } %>
	    </span>
    </div>
    <ul id="CommentsHeader">
    	<li>Comments(<%= Model.Comments.Count %>)</li>
    	<li>TrackBacks(<%= Model.TrackBacks.Count %>)</li>
    </ul>
    <% foreach (var comment in Model.Comments) { %>
	    <div class="Comment">
	    	<h4><img src="/Images/comments-24.png" alt="Comment" /><%= comment.Author %></h4>
	    	<p>
	    		<%= comment.Content %>
	    	</p>
	    </div>
    <% } %>
    	<div class="AddComment">
    		<h4><img src="/Images/comments-24.png" alt="Comment" />Write a comment</h4>
    		<% if(Request.IsAuthenticated) { %>
            	<form id="CommentForm">
		    		<p>
		    			<input type="hidden" name="postId" id="postId" value="<%= Model.Id %>" />
		    			<textarea name="content" id="content" cols="69" rows="10" tabindex="1">
		    			</textarea>
		    		</p>
		    		<p>
						<input type="text" name="author" id="author" value="" size="22" tabindex="2" />
						<span>Name</span> 
					</p>
					<p>
						<input type="text" name="email" id="email" value="" size="22" tabindex="3" />
						<span>Email</span> 
					</p>
					<p>
						<input name="submit" type="button" id="submit" tabindex="4" accesskey="s" value="Send" />
					</p>
				</form>
            <% } else {%>
            	<p>
					You have to log in to comment.
				</p>
            <% } %>
    		
    	</div>
</asp:Content>
<asp:Content id="ctnColumn2" runat="server" ContentPlaceHolderID="Column2">
	<div id="PhotoFrame">
        <img src="/Images/shapeimage_2.png" alt="Kristian Gundry" />
    </div>
    <div id="Archive">
        <h4>Archive</h4>
        <ul>
        	<% for(int i=0;i<6;i++) { %>
        		<%if(((IEnumerable<Plain.Demo.Blog.Business.Post>)ViewData["posts"]).Where(x=>x.Published.Value.Year == DateTime.Now.Year - i).Count()> 0){%>
            		<li><a href="#" class="Year"><%= DateTime.Now.Year - i %> (<%= ((IEnumerable<Plain.Demo.Blog.Business.Post>)ViewData["posts"]).Where(x=>x.Published.Value.Year == DateTime.Now.Year - i).Count()%>)</a></li>
            	<% } else{%>
            		<li><span><%= DateTime.Now.Year - i %> (<%= ((IEnumerable<Plain.Demo.Blog.Business.Post>)ViewData["posts"]).Where(x=>x.Published.Value.Year == DateTime.Now.Year - i).Count()%>)</span></li>
            	<% } %>
            <% } %>
        </ul>
        <h6><span>&lt;&lt;</span> <span>year</span> <a href="#">&gt;&gt;</a></h6>
    </div>
</asp:Content>